#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/10/6 12:13
# @Author  : AshJo
# @Desc    : 多进程模块
# @Filename: process_demo.py.py
# @Version : v1.0
"""

from multiprocessing import Process
import os
import time
import random


def func(name, age):
    print(os.getpid(), os.getppid(), f'给{age}岁的{name}发送一封邮件')
    time.sleep(random.random())


if __name__ == '__main__':
    print('main: ', os.getpid(), os.getppid())
    arg_lst = [('Tom', 18), ('Jerry', 21), ('Betty', 25), ('Angle', 23)]
    p_lst = []
    for arg in arg_lst:
        p = Process(target=func, args=arg)
        p.start()
        p_lst.append(p)
    for p in p_lst: p.join() # 阻塞 等待子进程执行完毕
    print('Finish！')
